﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessTest.Chess.Items
{
    [Serializable]
    class PawnsItem : OneStepItem
    {
        public override string DisplayName=> IsBlack? "卒": "兵";

        public Boolean IsSuper { get; set; }

        protected override bool IsOverstep(Chessboard chessboard, int x, int y)
        {
            if (base.IsOverstep(chessboard, x, y))
                return true;
            //自己的国王
            KingItem theKing;
            if (IsBlack)
                theKing = chessboard. BlackKing;
            else
                theKing = chessboard.RedKing;

            //不能往回走
            if (Math.Abs(y - theKing.PositionY) < Math.Abs(PositionY - theKing.PositionY))
                return true;

            if (x != PositionX)
            {
                if (theKing.PositionY > 5)
                {
                    if (y >= 5)
                        return true;
                }
                else
                {
                    if (y <=4 )
                        return true;
                }
            }

            return false;
        }


        public override List<Point> GetOriginCanMoveList(Chessboard chessboard)
        {
            List<Point> list = new List<Point>();

            if (CanOriginMove(chessboard,PositionX + 1, PositionY))
                list.Add(new Point(PositionX + 1, PositionY));

            if (CanOriginMove(chessboard,PositionX - 1, PositionY))
                list.Add(new Point(PositionX - 1, PositionY));
            if (CanOriginMove(chessboard,PositionX, PositionY + 1))
                list.Add(new Point(PositionX, PositionY + 1));
            if (CanOriginMove(chessboard,PositionX, PositionY - 1))
                list.Add(new Point(PositionX, PositionY - 1));

            return list;
        }
        public override int Score { get => base.Score + (IsSuper?1:0);  }

    }
}
